package bestv.mvc1.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import bestv.mvc1.pojo.User;
import bestv.mvc1.service.HelloWorldService;

@Controller
@RequestMapping("/helloworld")
public class HelloWorldController {

	@Autowired
	private HelloWorldService helloWorldService;

	@RequestMapping("/getnewname.do")
	public String getnewname(User user1, HttpServletRequest request) {
		String newUserName = helloWorldService.getNewName(user1.getSname());
		request.setAttribute("newUserName", newUserName);
		return "helloworld/helloworld";
	}

	@RequestMapping("/userlist.do")
	@ResponseBody
	public List<User> getUsers(HttpServletResponse response) {
		List<User> users = new ArrayList<User>();
		User user1 = new User();
		user1.setSname("张三");
		user1.setSpwd("111");
		users.add(user1);
		User user2 = new User();
		user2.setSname("李四");
		user2.setSpwd("222");
		users.add(user2);
		//JSONArray jsonArray = JSONArray.fromObject(users);
		//System.out.println(jsonArray);
		return users;
	}

}